use criterion::{black_box, criterion_group, criterion_main, Criterion};

fn odd_fibnacci_sum(threshold: u32) -> u32 {
    let (mut a, mut b) = (0, 1);
    let mut sum = 1;
    while b < threshold {
        if b % 2 == 1 {
            sum += b;
        }
        (a, b) = (b, a + b);
    }
    sum
}

pub fn criterion_benchmark(c: &mut Criterion) {
    c.bench_function("fib simple 4", |b| {
        b.iter(|| odd_fibnacci_sum(black_box(4)))
    });
    c.bench_function("fib simple 16", |b| {
        b.iter(|| odd_fibnacci_sum(black_box(16)))
    });
    c.bench_function("fib simple 32", |b| {
        b.iter(|| odd_fibnacci_sum(black_box(32)))
    });
    c.bench_function("fib simple 0xFFFFFF", |b| {
        b.iter(|| odd_fibnacci_sum(black_box(0xFFFFFF)))
    });
    c.bench_function("fib simple 0x7FFFFFFF", |b| {
        b.iter(|| odd_fibnacci_sum(black_box(0x7FFFFFFF)))
    });
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
